<?php

namespace plugin\ycMassage\app\controller;

use plugin\ycMassage\app\BaseController;
use plugin\ycMassage\app\model\MassageUserChannels;
use think\facade\Request;

class SalesmanController extends BaseController
{
    public function index()
    {
        $request=request();
        $id=$request->get('id');
        $model = MassageUserChannels::where(['id' => $id])->find();
        if(!$model){
            throw new \think\exception\HttpException(404, '未找到渠道商申请信息');
        }
        $saas_appid=$model->saas_appid;
        $domain = getHpConfig('domain', (int)$model->saas_appid, 'plugins_domains');
        if ($model->uid) {
            $channels = getHpConfig('', $model->saas_appid, 'channels');
            $valid_time = 0;
            if (isset($channels['valid_time'])) {
                $valid_time = $channels['valid_time'];
            }
            $url = $domain . "/app/ycMassage/#/pages/index/index?appid={$saas_appid}&channels_id={$id}&valid_time={$valid_time}";
        } else {
            $url = $domain . "/app/ycMassage/#/channels/pages/user/apply?appid={$saas_appid}&id=" . $model->id;
        }
        return redirect($url);
    }
}